package com.jic.market.controller.manage;

import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.market.entity.Material;
import com.jic.market.request.*;
import com.jic.market.response.MaterialCategoryTreeResponse;
import com.jic.market.service.MaterialCategoryService;
import com.jic.market.service.MaterialService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 素材管理
 */
@RestController
@RequestMapping("/material")
public class MaterialManageController {

    @Autowired
    private MaterialService materialService;

    @Autowired
    private MaterialCategoryService materialCategoryService;

    @ApiOperation(value = "查询素材树")
    @RequestMapping(value = "queryTree", method = RequestMethod.POST)
    public RestResult<MaterialCategoryTreeResponse> queryTree(@RequestBody MaterialCategoryTreeRequest request) {
        return materialCategoryService.queryTree(request);
    }

    @ApiOperation(value = "分页查询")
    @RequestMapping(value = "queryPage", method = RequestMethod.POST)
    public RestResult<PageResult<Material>> queryPage(@RequestBody MaterialQueryRequest request) {
        return materialService.queryPage(request);
    }

    @ApiOperation(value = "添加")
    @RequestMapping(value = "add", method = RequestMethod.POST)
    public RestResult<Long> add(@RequestBody MaterialAddRequest request) {
        return materialService.add(request);
    }

    @ApiOperation(value = "编辑")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public RestResult<Long> update(@RequestBody MaterialEditRequest request) {
        return materialService.update(request);
    }

    @ApiOperation(value = "删除")
    @RequestMapping(value = "delete", method = RequestMethod.POST)
    public RestResult<Long> delete(@RequestBody MaterialDeleteRequest request) {
        return materialService.delete(request);
    }

}
